MDEV-39791: Handle count aggregate optimization for replay purpose#5145
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for recording and replaying count aggregate contexts (count_agg) within the optimizer context store/replay framework. While the implementation successfully integrates the new structures and serialization routines, several critical issues must be addressed. Most notably, there is a type confusion vulnerability in opt_sum.cc where a cast to Item_field* is performed without verifying the item type, which could lead to server crashes. Additionally, there are bugs involving the serialization of a pointer instead of the actual count value, incorrect string appending of a ulong counter, potential counter desynchronization during OOM events, and swapped error messages in the JSON parsing routines.
5f4ea85 to
65823a0
Compare
039fe52 to
90b9f07
Compare
438acc1 to
fabfa22
Compare
^ this is not caught by capture at all. To check that I do have your patch, etc: Now, this does hits a breakpoint in Optimizer_context_recorder::record_count_agg, as expected. |
This is a bad name. Please change to |
fabfa22 to
80c607d
Compare
sure. changed it. |
Yes, count(*) would also be hitting the opt_sum_query() call, and we could get the count. However, I see one problem. How could we get the table information if the expression inside the count() is not a field_type? For count(a) I could get table info from field a. |
The optimizer already handles all this. create table t10 (a int, b int not null) engine=myisam;
insert into t10 select seq,seq from seq_1_to_10;
create table t11 like t10;
insert into t11 select seq, seq from seq_1_to_3;If the expression is not NULLable, it doesn't matter what specific columns are used in it: NULL-able expression disqualifies the optimization: But do we need to think about all these details now? AFAIU what we need to do is to place hooks to save and/or infuse the record count in |
okay. So, get_exact_record_count() wouldn't take any arguments such as TABLE*. Instead, depending on the invocation/call number we return the count. Is it? |
1299232 to
5c9ac44
Compare
During replay, when get_exact_record_count() is invoked from opt_sum_query(), hook the recorded table rows from the parsed context for each table, during the calculation of count.
5c9ac44 to
cf18a5b
Compare
cf18a5b
into
bb-12.3-MDEV-39368-test-replay
During replay, when get_exact_record_count() is invoked from opt_sum_query(),
hook the recorded table rows from the parsed context for each table,
during the calculation of count.